#lang racket

(define (* a b)
  (define (double x) (+ x x))
  (define (halve x) (/ x 2))
  (define (even x) (= (remainder x 2) 0))

  ;迭代算法
  (define (iter a b result)
    (cond ((= b 0) result)
          ((even b) (iter (double a) (halve b) result))
          (else (iter a (- b 1) (+ a result)))))

  (iter a b 0)
  ;递归算法
;  (cond ((= b 0) 0)
;        ((even b) (* (double a) (halve b)))
;        (else (+ a (* (double a) (halve (- b 1))))))
  )
